Skip to content

Conversation

@dommccarty
Copy link

This now checks for a lot more possible errors. Also expands the Response class to include the response headers, and some more metadata about the response.

Copy link
Member

@iVariable iVariable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello!
Thanks for the PR! Please check comments that I left.

I really like that u've added must-retry, wait-seconds and response headers 👍

But there are also several things which are questionable to me like:

  • having 2 more or less same errors (server-side)
  • helpers like some* (IdsInvalid, IdsNew). Not totally convinced that they are useless, but also not sure that they are needed, as implementation is super trivial and all devs can write them outside
  • pls add tests for newly added methods

PS: also please make use of PSR-2 (http://www.php-fig.org/psr/psr-2/)
PPS: Also thanks for letting me know that this bundle is still in use :) I'll setup CI checks today for codestyle and tests and overall will do a cleanup

README.md Outdated

if ($response->existsInvalidDataKey()) {
//You used a reserved data key
$error_msg = 'Invalid data key in payload. ' . json_encode($message->getNotification());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls, fix indentation.

README.md Outdated

if ($response->existsMismatchSenderId()) {
//A client sent the wrong senderId when it registered for pushes
$error_msg = 'Mismatch senderId. Problem clients are ' . json_encode($response->getMismatchSenderIdIds());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls, fix indentation

README.md Outdated

if ($response->existsInvalidDataKey()) {
//You used a reserved data key
$error_msg = 'Invalid data key in payload. ' . json_encode($message->getNotification());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls, fix indentation

README.md Outdated

if ($response->existsMismatchSenderId()) {
//A client sent the wrong senderId when it registered for pushes
$error_msg = 'Mismatch senderId. Problem clients are ' . json_encode($response->getMismatchSenderIdIds());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls, fix indentation

const UNKNOWN_ERROR = 4;
const MALFORMED_RESPONSE = 5;
const INTERNAL_SERVER_ERROR = 6;
const SERVICE_UNAVAILABLE = 7;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need specific SERVICE_UNAVAILABLE? Is it that different from INTERNAL_SERVER_ERROR?
Do you have any specific actions needed to be taken from client perspective in case 1 error and in case of another?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, removing. SERVICE_UNAVAILABLE seems more serious and we might want to shut off our push notifications for a while in that case. But someone can always just check the response headers now if they want to implement different handling.

throw new Exception("Unknown error. ".$resultBody, Exception::UNKNOWN_ERROR);
break;

if ($resultHttpCode == "200") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understood u've converted switch to if-elseif only for the sake of having "INTERNAL_ERROR" and "SERVICE_UNAVAILABLE".

Switch readability is a bit better, please convert if-elseif to switch(true) {} statement.

And speaking of those 2 "different" errors. Do we really need to distinguish between those 2 errors from client perspective? Ain't it enough to just know, that problem exists from "the other side". We can't really do anything about it in any case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I'll put it back to your version. Now that response headers are included in the Response object the programmer can do the more fine-grained analysis himself if he wants.

else {
throw new Exception("Unknown error. ". $resultBody, Exception::UNKNOWN_ERROR);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls remove redundant new lines

'collapse_key' => 'getCollapseKey',
'data' => 'getData',
'notification' => 'getNotification',
'notification' => 'getNotification',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

return $data;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation


}

/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls remove license comment

@dommccarty
Copy link
Author

OK, tests added and passed! What do you think?

@dommccarty
Copy link
Author

GCM is currently responding to a request with an invalid data key with a HTTP response code 400, though in the documentation they say we should also be prepared to handle a response code 200 with the "error" on the individual response entries being "InvalidDataKey".

Also they don't specify which response code they'll use if there's a Retry-After, but presumably it will be 503. In any case (haha), I changed it so if we get a Retry-After no Response object is created, because it's not necessary. So the Retry-After stuff has gone into the Exception.

What do you think about these changes?

@dommccarty dommccarty closed this Jan 24, 2017
@dommccarty dommccarty reopened this Jan 24, 2017
@dommccarty
Copy link
Author

Whoops, hadn't pushed that button before ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants